package com.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.study.dao.entity.MovieUser;
import com.study.feign.EurekaFeignClient;
import com.study.feign.UserFeignClient;

import ch.qos.logback.core.net.SyslogOutputStream;

@RestController
public class MovieUserController {
	
	@Autowired
	UserFeignClient userFeignClient;
	
	@Autowired
	EurekaFeignClient eurekaFeignClient;
	
	/**
	 * 使用restTemplate时：
	 * MovieUser movieUser = restTemplate.getForObject("http://sunxj-microservice-provider-user/simple/" + id, MovieUser.class);
	 * 
	 * 使用FeignClient接口时：
	 * 如下
	 */
	@GetMapping("/feign/{id}")
	public MovieUser selectById(@PathVariable("id") int id) {
		MovieUser movieUser =  userFeignClient.selectById(id);
		return movieUser;
	}
	
	/*
		http://localhost:8085/sunxj-microservice-provider-user
	 */
	@GetMapping("/{serviceName}")
	public String findServiceInfoFromEurekaByServiceName(@PathVariable("serviceName") String serviceName) {
		String serviceInfo = eurekaFeignClient.findServiceInfoFromEurekaByServiceName(serviceName);
		System.out.println("serviceInfo: " + serviceInfo);
		return serviceInfo;
	}
	
}
